package org.i0o.webplus.commons.util.populator.converters;

import java.math.BigDecimal;

/**
 * @author <a href="mailto:781131@gmail.com">HTF</a>
 * @version 2011-1-9
 */
public final class BigDecimalConverter extends BaseConverter {

	@Override
	protected Object convertToType(Object value, Class<?> targetType, Object... configs) {
		if (value == null) {
			return new BigDecimal(0L);
		}
		if (value instanceof BigDecimal) {
			return (BigDecimal) value;
		}
		if (value instanceof Number) {
			return BigDecimal.valueOf(((Number) value).doubleValue());
		}
		if (value instanceof Boolean) {
			return BigDecimal.valueOf(((Boolean) value) ? 1 : 0);
		}
		if (value instanceof Character) {
			return BigDecimal.valueOf((Character) value);
		}
		return null;
	}

	@Override
	protected Class<?> getDefaultType() {
		return BigDecimal.class;
	}

}
